<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="../../plugins/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../css/fa.css"/>
    <link rel="stylesheet" href="../../css/icon.css"/>
    <link rel="stylesheet" href="../../css/ares_animate.min.css"/>
    <link rel="stylesheet" href="../../css/ares_hover_variant.min.css"/>
    <link rel="stylesheet" href="../../css/ares_reboot.css"/>
    <link rel="stylesheet" href="../../css/app.min.css"/>
    <link rel="stylesheet" href="../../css/iframe.css"/>
    <link rel="stylesheet" href="../../css/print.css"/>
    <style>

    </style>
</head>
<body class="print-wrap">
<button id="print-btn" class="layui-btn layui-btn-xs ares-d-print-none ares-position-absolute ares-absolute-tr-offset">打印</button>
<h3>基本信息</h3>
<div class="ares-mb emr-info ares-border-bottom"></div>
<div class="creator-wrap ares-text-right"></div>
<h3>处方内容</h3>
<div id="prcp-content-wrap" class="ares-px"></div>


<script type="text/javascript" src="../../plugins/layui/layui.js"></script>
<script type="text/javascript" src="../../aresExtends/config/layuiConfig.js"></script>
<script>
    var init;
    layui.use(['dateFilters', 'commonServices', 'greyServices', 'qs', 'printArea'], function (dateFilters, commonServices, greyServices, qs, printArea) {
        var emrId, selectPrcpId, isReferralHistory;
        init = function () {
            var localHash = location.hash,
                queryStr = localHash.split('?')[1],
                routerParams = top.layui.routers.params,
                routerQuery = queryStr ? qs.parse(queryStr) : {};
            console.log(localHash, queryStr, routerParams, routerQuery)
            emrId = routerParams.emrId;
            selectPrcpId = routerQuery.selectPrcpId;
            isReferralHistory = routerQuery.isReferralHistory;
            if(!emrId || !selectPrcpId) return;   //hack 取消打印时会报错
            getPatientInfo();
            getDetail();
        }
        init();
        /**
         * @author: ares
         * @date: 2021/3/30 11:51
         * @description: 打印
         */
        $('#print-btn').on('click', function () {
            $('.print-wrap').printArea();
        })

        /**
         * @author: ares
         * @date: 2021/3/30 14:44
         * @description: 获取处方详情
         */
        function getDetail() {
            greyServices.grey_get_prescription(selectPrcpId, emrId, isReferralHistory).then(function (res) {
                var data = res.data,
                    description = data.description;
                $('.creator-wrap').empty().append('<b>创建者: ' + data.creator.name + '</b>' +
                    '<b class="ares-ml-lg">创建时间: ' + dateFilters.dateTimeFormat(data.create_time) + '</b>');

                if (data.is_private == "0") {
                    console.log("历史数据", data)
                } else if (data.is_private == "1") {
                    console.log("pad")
                    renderPrivate(JSON.parse(description));
                }

            });
        }

        function renderPrivate(data) {
            var $wrap = $('#prcp-content-wrap'),
                $fragment = $(document.createDocumentFragment()),
                problem = data.pro_list,
                trainingList = data.training_list,
                $problem = $('<div class="problem">' +
                    '<div class="problem">当前主要问题: ' + (problem.problem_content || "——") + '</div>' +
                    '<div class="problem">短期目标: ' + (problem.short_objective_content || "——") + '</div>' +
                    '<div class="problem">长期目标: ' + (problem.lang_objective_content || "——") + '</div>' +
                    '</div>');
            $fragment.append($problem);

            $.each(trainingList, function (index, list) {
                var $info = $('<div class="ares-mb">' +
                    '<div><b>' + list.prcp_item_type_name + '</b></div>' +
                    '<div class="ares-px">' +
                    '<span>治疗师: ' + list.therapist_name + '</span>' +
                    '<span class="ares-ml-lg">治疗频次: ' + list.treatment_frequency.txt + '</span>' +
                    '<span class="ares-ml-lg">治疗时间: ' + list.treatment_time.txt + '</span>' +
                    '<span class="ares-ml-lg">治疗次数: ' + list.treatment_times + '</span>' +
                    '</div>' +
                    '</div>'),
                    parts = list.part,
                    $parts = $('<div class="part"><b>治疗项目</b></div>');
                if (list.attention != "") $info.append('<div class="ares-px">注意事项: ' + list.attention + '</div>')

                $.each(parts, function (idx, part) {
                    var $part = $('<div class="ares-px">' +
                        '<span>' + part.title + ': </span>' +
                        '<span class="ares-ml-lg">治疗部位: ' + part.part + '</span>' +
                        '</div>');

                    if (part.method) $part.append('<span class="ares-ml-lg">治疗方法: ' + part.method + '</span>');
                    if (part.dosage) $part.append('<span class="ares-ml-lg">剂量: ' + part.dosage + '</span>');
                    $parts.append($part);
                })
                $fragment.append($info, $parts);
            })
            $wrap.empty().append($fragment);
        }

        /**
         * @author: ares
         * @date: 2021/3/10 10:49
         * @description: 获取患者基本信息
         */
        function getPatientInfo() {
            commonServices.getEmrInfoService(emrId, null, null, $('.emr-info'))
        }
    })
</script>

</body>
</html>